package com.fucking.great.context.config;

import cn.hutool.cache.Cache;
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.hutool.json.JSONObject;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.fucking.great.context.TxnContext;
import com.fucking.great.context.plun.Plug;
import com.fucking.great.context.plun.PlugFactory;

import java.util.Map;

/**
 * 配置缓存装饰器。
 * @see com.fucking.great.context.config.JetcacheTxnConfigerDecorator
 * @deprecated
 */
@Deprecated
public class CacheTxnConfigerDecorator extends AbstractTxnConfigerDecorator{
    public static final Log log = LogFactory.get();

    public CacheTxnConfigerDecorator(TxnConfiger txnConfiger) {
        super(txnConfiger);
    }
    //
    private static final int TIMEOUT = 60 * 10 * 1000;
    private static final Cache<String, PathConfigBean>  PATH_CACHE = CacheUtil.newTimedCache(TIMEOUT);;
    private static final Cache<String, SystemConfigBean> SYSTEM_CACHE = CacheUtil.newTimedCache(TIMEOUT);
    private static final Cache<String, Plug> PLUGFACTORY_CACHE = CacheUtil.newTimedCache(TIMEOUT);

    @Override
    public PathConfigBean getPathConfigBean(final String path) {
        return PATH_CACHE.get(path, () -> super.getPathConfigBean(path) );
    }

    @Override
    public SystemConfigBean getSystemConfigBean(final String systemName) {
        return SYSTEM_CACHE.get(systemName, () -> super.getSystemConfigBean(systemName) );
    }

    @Override
    public Plug getPlug(String name, String systemName) {
        return PLUGFACTORY_CACHE.get(systemName, () -> super.getPlug(name, systemName) );
    }
}
